<include file="./Application/Admin/View/Public/htmlheader.html"/>
<link rel="stylesheet" type="text/css" href="/Css/jquery.datetimepicker.css"/>
<include file="./Application/Admin/View/Public/header.html"/>
<include file="./Application/Admin/View/Public/left.html"/>

<style>
    .pagination {
        margin: 0;
    }
</style>
<ol class="breadcrumb">
    <li><a href="/Admin/Room">直播间列表</a></li>
    <li class="active">修改直播间</li>
</ol>
<form action="__ROOT__/Admin/Room/modifyRoom" method="post" enctype="multipart/form-data">
    <input type="hidden" name="id" value="{$room.id}">

    <div class="modal-body">
        <div class="row">
            <div class="col-lg-1 text-right"><p><span class="red">*</span>名称：</p></div>
            <div class="col-lg-3"><input type="text" name="name" class="form-control" value="{$room.name}"/></div>
        </div>
        <br/>
        <div class="row">
            <div class="col-lg-1 text-right"><p><span class="red">*</span>开播日期：</p></div>
            <div class="col-lg-3"><input type="text" name="beginTime" value="<php> echo date('Y-m-d H:i:s',$room['beginTime']) ; </php>" class="form-control" id="datetimepicker" /></div>
        </div>
        <br/>
        <div class="row">
            <div class="col-lg-1 text-right"><p>封面图片：</p></div>
            <div class="col-lg-3">
                <img src="{$room['image']}" height="100" />
                <input type="file" name="image" class="form-control"/></div>
        </div>
        <br/>

        <div class="row">
            <div class="col-lg-1 text-right"><p><span class="red">*</span>介绍：</p></div>
            <div class="col-lg-3">
                <textarea name="description" class="form-control" rows="5">{$room.description}</textarea>
            </div>
        </div>
        <br/>

        <div class="row">
            <div class="col-lg-1 text-right"><p><span class="red">*</span>所属分类：</p></div>
            <div class="col-lg-3">
                <select class="form-control" id="parentsCategoryIds">
                    <option value="0">选择分类</option>
                    <foreach name="parentsCategoryList" item="vo">
                        <option value="{$vo.id}">{$vo.name}</option>
                    </foreach>
                </select>
            </div>
            <div class="col-lg-3">
                <select class="form-control" name="categoryId" id="childCategory">
                </select>
            </div>
        </div>
        <br/>

        <div class="row">
            <div class="col-lg-1 text-right"><p><span class="red">*</span>主播：</p></div>
            <div class="col-lg-3">
                <select class="form-control" name="userId">
                    <option value="0">不设置主播</option>
                    <volist name="userList" id="vo">
                        <if condition="$vo.id eq $room['userId']">
                            <option value="{$vo.id}" selected>{$vo.username}</option>
                            <else />
                            <option value="{$vo.id}">{$vo.username}</option>
                        </if>
                    </volist>
                </select>
            </div>
        </div>
        <br/>

        <div class="row">
            <div class="col-lg-1 text-right"><span class="red">*</span>状态：</div>
            <div class="col-lg-3">
                <if condition="$room['status'] eq 0">
                    <input type="radio" name="status" value="0" checked> <span class="red">关闭</span>
                    <input type="radio" name="status" value="1"> <span class="green">起用</span>
                    <else />
                    <input type="radio" name="status" value="0"> <span class="red">关闭</span>
                    <input type="radio" name="status" value="1" checked> <span class="green">起用</span>
                </if>
            </div>
        </div>
        <br />
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="submit" class="btn btn-primary" id="addBtn" style="display: none">确定</button>
    </div>
</form>
<script>
    $("#status").val("{$room['status']}");

</script>
<script>
    $("#parentsCategoryIds").change(function () {
        var chlidCategorys = '{$childCategoryList}';
        var obj = eval('(' + chlidCategorys + ')');
        var parentsCategoryIds = $("#parentsCategoryIds").val();
        var childCategory = {};
        if (parentsCategoryIds > 0) {
            $.each(obj, function (index, data) {
                if (data.categoryId == parentsCategoryIds) {
                    childCategory[index] = data;
                }
            });
            $("#childCategory").html("");
            if (isNull(childCategory)) {

                $.each(childCategory, function (index, data) {
                    $("#childCategory").append("<option value=\"" + data.id + "\">" + data.name + "</option>");
                })
                $("#addBtn").show();
            } else {
                alert("不存在子分类，无法绑定分类");
                $("#addBtn").hide();
            }

        } else {
            alert("请选择分类!");
            $("#addBtn").hide();
        }
    })


    /**
     * 是否为空对象
     *
     * @param obj
     * @returns {boolean}
     */
    function isNull(obj) {
        var num = 0;
        $.each(obj, function (index, data) {
            num++;
        })
        if (num == 0) {
            return false;
        } else {
            return true;
        }
    }
    $("#status").val("{$room['status']}");
    $("#childCategory").append("<option value=\"{$findCategory['id']}\">{$findCategory['name']}</option>");
    $("#addBtn").show();
</script>
<script src="/Js/jquery.datetimepicker.js"></script>
<script>
    $('#datetimepicker').datetimepicker({
        format:'Y-m-d H:i:s',
    });
</script>
<include file="./Application/Admin/View/Public/footer.html"/>